package com.example.controller.sys;

import com.example.common.Message;
import com.example.model.ums.UmsAdmin;
import com.example.model.ums.UmsAdminRole;
import com.example.service.ums.UmsAdminRoleService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/sys/umsAdminRole")
@Slf4j
public class UmsAdminRoleController {

    @Autowired
    private UmsAdminRoleService service;

    /**
     * 条件查询集合
     * @param umsAdminRole
     * @return
     */
    @RequestMapping(value = "/findUmsAdminRolesByParam", method = RequestMethod.GET)
    @ResponseBody
    public Message findUmsAdminRolesByParam(UmsAdminRole umsAdminRole) {
        long startTime = System.currentTimeMillis();
        log.info("UmsAdminRoleController.findUmsAdminRolesByParam 入参 UmsAdminRole ->{},start by startTime ->{}", umsAdminRole, startTime);
        List<UmsAdminRole> umsAdmins = service.findUmsAdminRolesByParam(umsAdminRole);
        log.info("UmsAdminRoleController.findUmsAdminRolesByParam 耗时：{} ms", System.currentTimeMillis() - startTime);
        return Message.ok(umsAdmins);
    }

    /**
     * 条件查询单条
     * @param umsAdminRole
     * @return
     */
    @RequestMapping(value = "/findUmsAdminRoleByParam", method = RequestMethod.GET)
    @ResponseBody
    public Message findUmsAdminRoleByParam(UmsAdminRole umsAdminRole) {
        long startTime = System.currentTimeMillis();
        log.info("UmsAdminRoleController.findUmsAdminRoleByParam 入参 UmsAdminRole ->{},start by startTime ->{}", umsAdminRole, startTime);
        UmsAdminRole umsAdmins = service.findUmsAdminRoleByParam(umsAdminRole);
        log.info("UmsAdminRoleController.findUmsAdminRoleByParam 耗时：{} ms", System.currentTimeMillis() - startTime);
        return Message.ok(umsAdmins);
    }

    /**
     * 新增
     * @param umsAdminRole
     * @return
     */
    @RequestMapping(value = "/insert", method = RequestMethod.POST)
    public Message insert(@RequestBody UmsAdminRole umsAdminRole) throws Exception {
        long startTime = System.currentTimeMillis();
        log.info("UmsAdminRoleController.insert 入参 UmsAdminRole ->{},start by startTime ->{}", umsAdminRole, startTime);
        if (null == umsAdminRole) {
            throw new Exception("参数异常.");
        }
        Integer rlt = service.insert(umsAdminRole);
        log.info("UmsAdminRoleController.insert 耗时：{} ms", System.currentTimeMillis() - startTime);
        return Message.ok(rlt);
    }


}
